package com.zmn.plat.business.impl.expressage;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zmn.plat.model.dto.expressage.ExpressageDTO;
import com.zmn.plat.model.dto.expressage.ExpressageEntryDTO;

/**
 * @author quanjic
 * @version v1.0
 * @since 2018/11/27 14:18
 **/
@Deprecated
public class KuaiDi100Utils {

    /**
     * 解析
     *
     * @param jsonObject
     * @return
     */
    public static ExpressageDTO parse(JSONObject jsonObject) {

        if (jsonObject == null || StringUtils.isEmpty(jsonObject.getString("nu"))) {
            return null;
        }
        ExpressageDTO expressage = new ExpressageDTO();
        expressage.setCode(jsonObject.getString("nu"));
        expressage.setCompany(jsonObject.getString("com"));
        expressage.setState(jsonObject.getInteger("state"));

        JSONArray jsonArray = jsonObject.getJSONArray("data");
        if (jsonArray != null && jsonArray.size() > 0) {
            List<ExpressageEntryDTO> list = new ArrayList<>(jsonArray.size());
            JSONObject each = null;
            for (int i = 0; i < jsonArray.size(); i++) {
                each = jsonArray.getJSONObject(i);
                list.add(new ExpressageEntryDTO(each.getString("context"), each.getDate("ftime")));
            }
            expressage.setList(list);
        }
        return expressage;
    }

}
